﻿using ConfExpert.Forms.Base;
using ConfExpert.Utility;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraEditors.Repository;

using DevTeamIT;
using Extensions;
using System;

namespace ConfExpert.Forms.IT
{
    public partial class SetSirket : XForm
    {
        public SetSirket()
        {
            InitializeComponent();
        }

        public int SirketId = 0;
        private void SetSirket_Load(object sender, EventArgs e)
        {
            ((RepositoryItemGridLookUpEdit)gleSirket.Edit).Assign(RI(Rp.Sirket));
            if (Session.SirketId > 0)
                gleSirket.EditValue = Session.SirketId;
            gleSirket.EditValueChanged += gleSirket_EditValueChanged;
            btnTemizle.ItemClick += btnTemizle_ItemClick;
        }

        void btnTemizle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gleSirket.EditValue = null;
        }

        void gleSirket_EditValueChanged(object sender, EventArgs e)
        {
            Session.SirketId = gleSirket.EditValue.ToInt();
            foreach (RibbonPage p in AppSession.MainForm.Ribbon.Pages)
                foreach (RibbonPageGroup g in p.Groups)
                    foreach (BarItemLink bi in g.ItemLinks)
                        if (bi.Item.Caption.StartsWith("Şirket.Belirle"))
                        {
                            bi.Item.Caption = "Şirket.Belirle" +
                                (Session.SirketId > 0 ? " - " + RepositoryManager.dsi.Sirket.FindBySirketId(Session.SirketId).Name : string.Empty);
                            break;
                        }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}
